package com.bjc.core.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import com.bjc.base.core.annotation.PermissionPath;
import com.bjc.core.bean.request.UserRoleDimensionReqVO;
import com.bjc.core.bean.response.UserRoleDimensionVO;
import com.bjc.core.service.IUserRoleDimensionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 用户角色维度控制器
 * 
 * @author 许自辉
 * @date 2017年8月2日
 */
@RestController
@RequestMapping("api/cloud")
@PermissionPath("系统管理/角色")
@Api(value = "userRole-api", tags = { "用户角色维度相关接口" })
public class UserRoleDimensionController {

	@Autowired
	private IUserRoleDimensionService userRoleDimensionService;

	@ApiOperation("分页查询用户角色维度")
	@RequiresPermissions("userRoleDimension:findPage")
	@GetMapping("userRoleDimension/findPage")
	public ResultVO getUserRoleDimensionPage(@RequestParam("pageNum") int pageNum,
			@RequestParam("pageSize") int pageSize, UserRoleDimensionReqVO reqVO) {
		PageHelper.startPage(pageNum, pageSize);
		return ResultGenerator.getSuccess(new PageInfo<UserRoleDimensionVO>(userRoleDimensionService.getList(reqVO)));
	}

	@ApiOperation("批量添加用户角色维度")
	@RequiresPermissions("userRoleDimension:createList")
	@PostMapping("userRoleDimension/createList")
	public ResultVO createUserRoleDimensionList(@RequestBody List<UserRoleDimensionReqVO> reqVOs) {
		int count = userRoleDimensionService.insertList(reqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("批量删除用户角色维度")
	@RequiresPermissions("userRoleDimension:deleteList")
	@DeleteMapping("userRoleDimension/deleteList")
	public ResultVO deleteUserRoleDimensionList(@ApiParam(value = "角色id", required = true) @RequestBody int[] ids) {
		int count = userRoleDimensionService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}
}
